var dataObject = null;
var baseData = null;
var i18nLanguage = "";
var i18n = {
		baseData:null,
		dataObject:null,
		language: function(){
		    if(navigator.appName == "Netscape"){
		        var navLanguage = navigator.language;
		        console.log(navigator);
		        return changeLanguage(navLanguage);
		    }
		    return false;
		},
		getData:function(){		
			$.ajax({
				type: "GET",
				async: false,
			    url: $path+"sys/sysbasedata/getAllBaseData?language="+this.language(),
			    success: function(r){
			    	baseData = r.allBaseDataMap;
			    	if(window.localStorage){
			    		window.localStorage.baseData = JSON.stringify(r);
			    	}
			    	var obj= bulidObjecDate(r.allBaseDataMap);
			    	dataObject = obj;
				}
			});
		},
		init: function(){
			if(window.localStorage&&window.localStorage.baseData!=null){
				i18nLanguage = window.localStorage.language;
				baseData =  JSON.parse(localStorage.baseData).allBaseDataMap;
				var obj= bulidObjecDate(JSON.parse(localStorage.baseData).allBaseDataMap);
				dataObject = obj;
			}else{
				this.getData();
			}
		}
};
i18n.init();
//页面所有国际化元素
var pageData = dataObject.pageData;
var menuData = dataObject.menuData;
/**
 * 构建对象
 * @returns {___anonymous_dateObject}
 */
function bulidObjecDate(baseData){
	var pageData = {};
	for(var attr in baseData){
		pageData[attr]={};
		for(var j =0;j<baseData[attr].length;j++ ){
			pageData[attr][baseData[attr][j].key] = baseData[attr][j].value;
		}
	}
	return pageData;
}

function changeLanguage(navLanguage){
	var language = navLanguage;
	if(navLanguage == 'en-GB'){
		language = 'en-US';
	}else if(navLanguage == 'en'){
		language = 'en-US';
	}
	console.log("返回的语言是："+language);
	return language;
}

